package G1;

import java.io.PrintWriter;

public class HCT {
	private HCTNode<String> root;

	public HCT() {
		this.root = new HCTNode<String>("root");
	}
	public void addWord(String WORD,DOC doc) throws EmptyNodeException {
		HCTNode tmp = root;
		for(int i=0;i<WORD.length();i++){
			String key = WORD.charAt(i)+"";
			HCTNode<String> child = new HCTNode<String>(key);
			tmp = tmp.addChild(child, doc,(i==WORD.length()-1));
		}
	}
	public HCTNode search(String WORD) throws EmptyNodeException {
		HCTNode tmp = root;
		for(int i=0;i<WORD.length();i++){
			String key = WORD.charAt(i)+"";
			HCTNode<String> child = new HCTNode<String>(key);
			tmp = tmp.getChild(key);
		}
		return tmp;
	}
	
	public void printall(PrintWriter out) {
		//out.print("<ul>");
		root.printall(0,"", root, out);
		//out.print("</ul>");
	}
	public void printall(HCTNode target, PrintWriter out) {
		//out.print("<ul>");
		root.printall(0, "",target, out);
		//out.print("</ul>");
	}

}
